<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
        <title>项目9：字符游戏-智能蛇 - Adbean&#39;s Blog</title><meta name="Description" content="Adbean&#39;s Blog"><meta property="og:title" content="项目9：字符游戏-智能蛇" />
<meta property="og:description" content="本次项目的任务是让蛇有一定的智能，能通过算法具有 “感知-决策-行动” 的能力。 近一步，你可以做出华丽的字符界面，实现 人控蛇 与 智能蛇 抢食大战。 实" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://adbean.gitee.io/posts/my-ninth-project/" />
<meta property="og:image" content="https://adbean.gitee.io/logo.png"/>
<meta property="article:published_time" content="2020-12-27T10:05:47+08:00" />
<meta property="article:modified_time" content="2020-12-27T10:05:47+08:00" />
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://adbean.gitee.io/logo.png"/>

<meta name="twitter:title" content="项目9：字符游戏-智能蛇"/>
<meta name="twitter:description" content="本次项目的任务是让蛇有一定的智能，能通过算法具有 “感知-决策-行动” 的能力。 近一步，你可以做出华丽的字符界面，实现 人控蛇 与 智能蛇 抢食大战。 实"/>
<meta name="application-name" content="Adbean&#39;s Blog">
<meta name="apple-mobile-web-app-title" content="Adbean&#39;s Blog"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="icon" href="../../Owl.ico"><link rel="apple-touch-icon" sizes="180x180" href="../../apple-touch-icon.png"><link rel="mask-icon" href="../../safari-pinned-tab.svg" color="#5bbad5"><link rel="manifest" href="../../site.webmanifest"><link rel="canonical" href="https://adbean.gitee.io/posts/my-ninth-project/" /><link rel="prev" href="https://adbean.gitee.io/posts/my-eighth-project/" /><link rel="next" href="https://adbean.gitee.io/posts/my-tenth-project/" /><link rel="stylesheet" href="../../lib/normalize/normalize.min.css"><link rel="stylesheet" href="../../css/style.min.css"><link rel="stylesheet" href="../../lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="../../lib/animate/animate.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "项目9：字符游戏-智能蛇",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/adbean.gitee.io\/posts\/my-ninth-project\/"
        },"genre": "posts","keywords": "项目, C语言, 游戏, 贪吃蛇","wordcount":  3865 ,
        "url": "https:\/\/adbean.gitee.io\/posts\/my-ninth-project\/","datePublished": "2020-12-27T10:05:47+08:00","dateModified": "2020-12-27T10:05:47+08:00","publisher": {
            "@type": "Organization",
            "name": "Adbean"},"author": {
                "@type": "Person",
                "name": "Adbean"
            },"description": ""
    }
    </script></head>
    <body header-desktop="fixed" header-mobile="auto"><script type="text/javascript">(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('dark' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'dark' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="../../" title="Adbean&#39;s Blog"><img
        class="lazyload logo"
        src="../../svg/loading.min.svg"
        data-src="../../Owl.ico"
        data-srcset="../../Owl.ico, ../../Owl.ico 1.5x, ../../Owl.ico 2x"
        data-sizes="auto"
        alt="/Owl.ico"
        title="/Owl.ico" />Adbean&#39;s Blog</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="../../"> 主页 </a><a class="menu-item" href="../../posts/"> 文章 </a><a class="menu-item" href="../../posts/my-index/"> 索引 </a><a class="menu-item" href="../../tags/"> 标签 </a><a class="menu-item" href="../../categories/"> 分类 </a><span class="menu-item delimiter"></span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="../../" title="Adbean&#39;s Blog"><img
        class="lazyload logo"
        src="../../svg/loading.min.svg"
        data-src="../../Owl.ico"
        data-srcset="../../Owl.ico, ../../Owl.ico 1.5x, ../../Owl.ico 2x"
        data-sizes="auto"
        alt="/Owl.ico"
        title="/Owl.ico" />Adbean&#39;s Blog</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><a class="menu-item" href="../../" title="">主页</a><a class="menu-item" href="../../posts/" title="">文章</a><a class="menu-item" href="../../posts/my-index/" title="">索引</a><a class="menu-item" href="../../tags/" title="">标签</a><a class="menu-item" href="../../categories/" title="">分类</a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw"></i>
            </a></div>
    </div>
</header>
<div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div>
<main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single"><h1 class="single-title animated flipInX">项目9：字符游戏-智能蛇</h1><div class="post-meta">
            <div class="post-meta-line"><span class="post-author"><a href="https://adbean.gitee.io/" title="Author" target="_blank" rel="noopener noreffer author" class="author"><i class="fas fa-user-circle fa-fw"></i>Adbean</a></span>&nbsp;<span class="post-category">收录于 <a href="../../categories/%E9%A1%B9%E7%9B%AE/"><i class="far fa-folder fa-fw"></i>项目</a></span></div>
            <div class="post-meta-line"><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2020-12-27">2020-12-27</time>&nbsp;<i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 3865 字&nbsp;
                <i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 8 分钟&nbsp;</div>
        </div><div class="details toc" id="toc-static"  kept="">
                <div class="details-summary toc-title">
                    <span>目录</span>
                    <span><i class="details-icon fas fa-angle-right"></i></span>
                </div>
                <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li><a href="#实验目的">实验目的</a></li>
    <li><a href="#实验环境">实验环境</a></li>
    <li><a href="#控制输入输出设备">控制输入/输出设备</a>
      <ul>
        <li><a href="#vt-100-终端标准">VT 100 终端标准</a></li>
        <li><a href="#实现-kbhit">实现 kbhit()</a></li>
      </ul>
    </li>
    <li><a href="#编写智能算法">编写智能算法</a>
      <ul>
        <li><a href="#程序要求">程序要求</a></li>
        <li><a href="#源代码">源代码</a></li>
        <li><a href="#运行效果-2">运行效果</a></li>
      </ul>
    </li>
  </ul>
</nav></div>
            </div><div class="content" id="content"><p>本次项目的任务是让蛇有一定的智能，能通过算法具有 “<strong>感知-决策-行动</strong>” 的能力。</p>
<p>近一步，你可以做出华丽的字符界面，实现 <strong>人控蛇</strong> 与 <strong>智能蛇</strong> 抢食大战。</p>
<h2 id="实验目的">实验目的</h2>
<ul>
<li>了解 <strong>算法</strong> 与 <strong>智能</strong> 的关系</li>
<li>通过<strong>算法</strong>赋予蛇智能</li>
<li>了解 <strong>Linux IO</strong> 设计的控制</li>
</ul>
<h2 id="实验环境">实验环境</h2>
<ul>
<li><strong>Linux</strong> Only. 你可以选择 <strong>Unbutu</strong>、Centos 等发行版。</li>
<li>建议编辑环境 <strong>Vim</strong> 或 <strong>Vscode</strong>, 编译 <strong>gcc</strong></li>
<li>第一次使用 Linux，建议使用<strong>虚拟机</strong>。可以使用其他同学准备好的 Vbox 镜像
<blockquote>
<p>笔者的运行环境为 <strong>Ubuntu</strong> 20.04.1 LTS (Windows Subsystem for Linux (<strong>WSL</strong>) in Windows10)， <strong>gcc</strong> version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)</p>
</blockquote>
</li>
</ul>
<h2 id="控制输入输出设备">控制输入/输出设备</h2>
<p>你知道为什么一行代码要控制在 80（字符）列以内？ <a href="https://en.wikipedia.org/wiki/Characters_per_line" target="_blank" rel="noopener noreffer"><strong>原因是</strong></a> …</p>
<p>原来历史上读程序的<strong>卡片机</strong>只能读 80 个字符。当然，超过 80 个字符也打不出来阅读了。</p>
<p>那么一个语句超过 80 个字符怎么办？ <strong>续行符</strong></p>
<p>言归正传，早期的输出设备显示器、打印机，输入设备键盘（打字机）都是 80 列行缓冲顺序输入和输出设备。即你打印文件时，打印机必须等收到行结束符，打印机才会动作。然而，输入/输出随着应用需求不断进化，字符界面控制与管理已经非常标准化了。</p>
<h3 id="vt-100-终端标准">VT 100 终端标准</h3>
<p>在字符终端上完成“<strong>清屏</strong>”、“<strong>修改光标位置</strong>”、“设置字符前景和背景色”等操作，是通过输出 <strong>esc</strong> 序列实现的。</p>
<p>对于 VT100 终端, printf(&quot;\033[2J&rdquo;) 就实现了清屏。</p>
<p>详细内容参见， <a href="https://www.cnblogs.com/zengjfgit/p/4373564.html" target="_blank" rel="noopener noreffer"><strong>C 语言与 VT100 控制码编程</strong></a></p>
<p><strong>sin-demo.c</strong> 的代码。（源代码较长，请<strong>展开</strong>查看）</p>
<div class="highlight"><pre class="chroma"><code class="language-c" data-lang="c"><span class="cm">/******************************************************************
</span><span class="cm"> *                        sinDemo
</span><span class="cm"> *
</span><span class="cm"> *   1. 本Demo主要目标是为了实现在终端下实现sin函数的动态效果;
</span><span class="cm"> *   2. 本Demo之前是使用shell tput和C语言实现的,这次将其改为
</span><span class="cm"> *       C语言+VT100控制码的形式;
</span><span class="cm"> *
</span><span class="cm"> *                              2015-3-27 阴 深圳  曾剑峰
</span><span class="cm"> *
</span><span class="cm"> *****************************************************************/</span>
 <span class="cp">#include</span> <span class="cpf">&lt;stdio.h&gt;</span><span class="cp">
</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;math.h&gt;</span><span class="cp">
</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;unistd.h&gt;</span><span class="cp">
</span><span class="cp"></span>
 <span class="cm">/**
</span><span class="cm">  * 定义圆周率的值
</span><span class="cm">  */</span>
 <span class="cp">#define PI  3.14
</span><span class="cp"></span> <span class="cm">/**
</span><span class="cm">  * 本Demo中假设sin曲线周期为20,幅值也是20,幅值分正负幅值,
</span><span class="cm">  * 所以后面的很多地方有SIN_AMPLITUDE*2,也就是Y轴方向上的值.
</span><span class="cm">  */</span>
 <span class="cp">#define SIN_AMPLITUDE  20
</span><span class="cp"></span> <span class="cm">/**
</span><span class="cm">  * 定义每次刷新图形时间间隔为100ms
</span><span class="cm">  */</span>
 <span class="cp">#define DELAY_TIME  100000
</span><span class="cp"></span> <span class="cm">/**
</span><span class="cm">  * 定义圆的一周角度为360度
</span><span class="cm">  */</span>
 <span class="cp">#define TRIANGLE  360.0
</span><span class="cp"></span> <span class="cm">/**
</span><span class="cm">  * 输出的时候,数字行放在哪一行,也就是输出图形中的这行数字:
</span><span class="cm">  *   0123456789012345678901234567890123456789
</span><span class="cm">  * 本Demo中把上面这行数字放在界面的第3行
</span><span class="cm">  */</span>
 <span class="cp">#define Y_NUMBER_BEGIN_LINE  3
</span><span class="cp"></span> <span class="cm">/**
</span><span class="cm">  * 在本Demo中,图形就在上面数字行的下一行,也就是输出图形中如下面的内容:
</span><span class="cm">  *     0000    --------------------@--------------------&gt; Y
</span><span class="cm">  *     0001                        |-----*
</span><span class="cm">  *     0002                        |----------*
</span><span class="cm">  *     0003                        |---------------*
</span><span class="cm">  *     0004                        |------------------*
</span><span class="cm">  *     0005                        |------------------*
</span><span class="cm">  *     0006                        |------------------*
</span><span class="cm">  *     0007                        |---------------*
</span><span class="cm">  *     0008                        |----------*
</span><span class="cm">  *     0009                        |-----*
</span><span class="cm">  *     0010                        *
</span><span class="cm">  *     0011                  *-----|
</span><span class="cm">  *     0012             *----------|
</span><span class="cm">  *     0013        *---------------|
</span><span class="cm">  *     0014     *------------------|
</span><span class="cm">  *     0015     *------------------|
</span><span class="cm">  *     0016     *------------------|
</span><span class="cm">  *     0017        *---------------|
</span><span class="cm">  *     0018             *----------|
</span><span class="cm">  *     0019                  *-----|
</span><span class="cm">  *     0020                        V X
</span><span class="cm">  */</span>
 <span class="cp">#define SIN_GRAPH_BEGIN_LINE (Y_NUMBER_BEGIN_LINE+1)
</span><span class="cp"></span>
 <span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span><span class="o">*</span> <span class="n">argv</span><span class="p">[]){</span>

     <span class="cm">/**
</span><span class="cm">      * 局部变量说明:
</span><span class="cm">      *     1. i                 : 主要用于循环计算;
</span><span class="cm">      *     2. lineNumber        : 用于保存行号;
</span><span class="cm">      *     3. offsetCenter      : 用于保存sin曲线上的点的相对于中心轴的偏移;
</span><span class="cm">      *     4. nextInitAngle     : 保存下一屏要输出图形的初始角度制角度(如30度);
</span><span class="cm">      *     5. currentInitAngle  : 当前一屏要输出的图形的初始角度制角度(如30度);
</span><span class="cm">      *     6. currentInitradian : 当前一屏要输出的图形的初始弧度制弧度(如PI/6)
</span><span class="cm">      *                            根据currentInitAngle换算而来,因为sin函数需要
</span><span class="cm">      *                            角度制进行求值;
</span><span class="cm">      *
</span><span class="cm">      */</span>
     <span class="kt">int</span>    <span class="n">i</span>                   <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
     <span class="kt">int</span>    <span class="n">lineNumber</span>          <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
     <span class="kt">int</span>    <span class="n">offsetCenter</span>        <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
     <span class="kt">int</span>    <span class="n">nextInitAngle</span>       <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
     <span class="kt">double</span> <span class="n">currentInitAngle</span>    <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
     <span class="kt">double</span> <span class="n">currentInitradian</span>   <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>

     <span class="c1">//软件开始运行,清一次屏,保证屏幕上没有无关内容
</span><span class="c1"></span>     <span class="n">printf</span><span class="p">(</span><span class="s">&#34;</span><span class="se">\033</span><span class="s">[2J&#34;</span><span class="p">);</span>

     <span class="c1">//输出标题,因为这个软件名字叫: SinDemo
</span><span class="c1"></span>     <span class="n">printf</span><span class="p">(</span><span class="s">&#34;</span><span class="se">\033</span><span class="s">[1;1H                       | SinDemo |</span><span class="se">\t</span><span class="s">&#34;</span><span class="p">);</span>

     <span class="cm">/**
</span><span class="cm">      * 这里主要是完成那一行重复的0-9,SIN_AMPLITUDE*2是因为sin曲线的
</span><span class="cm">      * 最高点和最低点是2倍的幅值
</span><span class="cm">      */</span>
     <span class="n">printf</span><span class="p">(</span><span class="s">&#34;</span><span class="se">\033</span><span class="s">[%d;1H</span><span class="se">\t</span><span class="s">&#34;</span><span class="p">,</span> <span class="n">Y_NUMBER_BEGIN_LINE</span><span class="p">);</span>
     <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">SIN_AMPLITUDE</span><span class="o">*</span><span class="mi">2</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
         <span class="n">printf</span><span class="p">(</span><span class="s">&#34;%d&#34;</span><span class="p">,</span> <span class="n">i</span><span class="o">%</span><span class="mi">10</span><span class="p">);</span>
     <span class="n">printf</span><span class="p">(</span><span class="s">&#34;</span><span class="se">\n</span><span class="s">&#34;</span><span class="p">);</span>

     <span class="cm">/**
</span><span class="cm">      * while循环主要完成内容:
</span><span class="cm">      *     1. 每次循环对局部变量重新初始化;
</span><span class="cm">      *     2. 将下一屏图形的初始角度赋值给当前的图形初始角;
</span><span class="cm">      *     3. 将下一屏图形的初始角度加上间隔角度(TRIANGLE/SIN_AMPLITUDE),
</span><span class="cm">      *        TRIANGLE/SIN_AMPLITUDE在本Demo中是360/20=18度,就相当于X轴
</span><span class="cm">      *        每格代表18度
</span><span class="cm">      *     2. 调整光标到固定的位置;
</span><span class="cm">      *     3. 重新绘制整屏图形;
</span><span class="cm">      */</span>
     <span class="k">while</span><span class="p">(</span><span class="mi">1</span><span class="p">){</span>

         <span class="c1">//重新初始化局部变量,因为每一屏图形都像一个新的开始
</span><span class="c1"></span>         <span class="n">i</span>                  <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
         <span class="n">offsetCenter</span>       <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
         <span class="n">lineNumber</span>         <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
         <span class="n">currentInitradian</span>  <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>

         <span class="c1">//从nextInitAngle中获取当前的初始化角度
</span><span class="c1"></span>         <span class="n">currentInitAngle</span>   <span class="o">=</span>  <span class="n">nextInitAngle</span><span class="p">;</span>

         <span class="c1">//为下一次循环提供下一次的初始化角度
</span><span class="c1"></span>         <span class="n">nextInitAngle</span>     <span class="o">+=</span> <span class="n">TRIANGLE</span><span class="o">/</span><span class="n">SIN_AMPLITUDE</span><span class="p">;</span>

         <span class="c1">//将光标移动到开始绘图的位置去
</span><span class="c1"></span>         <span class="n">printf</span><span class="p">(</span><span class="s">&#34;</span><span class="se">\033</span><span class="s">[%d;1H&#34;</span><span class="p">,</span> <span class="n">SIN_GRAPH_BEGIN_LINE</span><span class="p">);</span>

         <span class="cm">/**
</span><span class="cm">          * 根据不同的情况绘制图形, 每一次循环,就是绘制了图形中的一行
</span><span class="cm">          */</span>
         <span class="k">while</span><span class="p">(</span><span class="mi">1</span><span class="p">){</span>
             <span class="c1">//判断是不是最后一行,lineNumber起始行是从0开始
</span><span class="c1"></span>             <span class="k">if</span><span class="p">(</span><span class="n">lineNumber</span> <span class="o">==</span> <span class="n">SIN_AMPLITUDE</span><span class="p">){</span>
                 <span class="c1">//打印最后一行前面的数字行号
</span><span class="c1"></span>                 <span class="n">printf</span><span class="p">(</span><span class="s">&#34;</span><span class="se">\033</span><span class="s">[%d;1H%04d</span><span class="se">\t</span><span class="s">&#34;</span><span class="p">,</span> <span class="n">lineNumber</span><span class="o">+</span><span class="n">SIN_GRAPH_BEGIN_LINE</span><span class="p">,</span> <span class="n">lineNumber</span><span class="p">);</span>
                 <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">SIN_AMPLITUDE</span><span class="o">*</span><span class="mi">2</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span>
                     <span class="cm">/**
</span><span class="cm">                      * 判断是否到达中间位置,因为中间位置要放V的箭头,同时在旁边输出一个X,
</span><span class="cm">                      * 代表这是X轴方向.
</span><span class="cm">                      */</span>
                     <span class="n">i</span> <span class="o">==</span> <span class="n">SIN_AMPLITUDE</span> <span class="o">?</span> <span class="n">printf</span><span class="p">(</span><span class="s">&#34;V X&#34;</span><span class="p">)</span> <span class="o">:</span> <span class="n">printf</span><span class="p">(</span><span class="s">&#34; &#34;</span><span class="p">);</span>
                 <span class="k">break</span><span class="p">;</span>
             <span class="p">}</span>


             <span class="cm">/**
</span><span class="cm">              * 对currentInitAngle角度进行修整,比如370度和10度是对应相同的sin值
</span><span class="cm">              * 其实这一步可以不用,但是这里保留了,后面是将currentInitAngle角度制的值
</span><span class="cm">              * 换算成对应的弧度制的值,便于sin求值.
</span><span class="cm">              */</span>
             <span class="n">currentInitAngle</span> <span class="o">=</span> <span class="p">((</span><span class="kt">int</span><span class="p">)</span><span class="n">currentInitAngle</span><span class="p">)</span><span class="o">%</span><span class="p">((</span><span class="kt">int</span><span class="p">)</span><span class="n">TRIANGLE</span><span class="p">);</span>
             <span class="n">currentInitradian</span> <span class="o">=</span> <span class="n">currentInitAngle</span><span class="o">/</span><span class="p">(</span><span class="n">TRIANGLE</span><span class="o">/</span><span class="mi">2</span><span class="p">)</span><span class="o">*</span><span class="n">PI</span><span class="p">;</span>

             <span class="cm">/**
</span><span class="cm">              * 算出当前次currentInitradian对应的sin值,并乘以幅值SIN_AMPLITUDE,获取sin曲线
</span><span class="cm">              * 在Y轴上相对于中心轴的偏移offsetCenter,offsetCenter可能是正值,也可能是负值,
</span><span class="cm">              * 因为中心轴在中间.
</span><span class="cm">              */</span>
             <span class="n">offsetCenter</span> <span class="o">=</span> <span class="p">(</span><span class="kt">int</span><span class="p">)(</span><span class="n">sin</span><span class="p">(</span><span class="n">currentInitradian</span><span class="p">)</span><span class="o">*</span><span class="n">SIN_AMPLITUDE</span><span class="p">);</span>

             <span class="cm">/**
</span><span class="cm">              * 在正确的地方输出正确的行号   :)
</span><span class="cm">              */</span>
             <span class="n">printf</span><span class="p">(</span><span class="s">&#34;</span><span class="se">\033</span><span class="s">[%d;1H%04d&#34;</span><span class="p">,</span> <span class="n">lineNumber</span><span class="o">+</span><span class="n">SIN_GRAPH_BEGIN_LINE</span><span class="p">,</span> <span class="n">lineNumber</span><span class="p">);</span>

             <span class="c1">//用一个制表符,给出行号与图形的空间距离
</span><span class="c1"></span>             <span class="n">printf</span><span class="p">(</span><span class="s">&#34;</span><span class="se">\t</span><span class="s">&#34;</span><span class="p">);</span>

             <span class="cm">/**
</span><span class="cm">              * 第一行,和其他的行不一样,有区别,输出结果如下:
</span><span class="cm">              * 0000    ------------@-------+--------------------&gt; Y
</span><span class="cm">              */</span>
             <span class="k">if</span><span class="p">(</span><span class="n">lineNumber</span> <span class="o">==</span> <span class="mi">0</span><span class="p">){</span>
                 <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">SIN_AMPLITUDE</span><span class="o">*</span><span class="mi">2</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">){</span>
                     <span class="cm">/**
</span><span class="cm">                      * 判断当前输出的字符位置是否是X,Y轴交叉的位置,如果是就输出&#39;+&#39;,
</span><span class="cm">                      * 不是就输出&#39;-&#39;
</span><span class="cm">                      */</span>
                     <span class="n">i</span> <span class="o">==</span> <span class="n">SIN_AMPLITUDE</span> <span class="o">?</span> <span class="n">printf</span><span class="p">(</span><span class="s">&#34;+&#34;</span><span class="p">)</span> <span class="o">:</span> <span class="n">printf</span><span class="p">(</span><span class="s">&#34;-&#34;</span><span class="p">);</span>
                     <span class="cm">/**
</span><span class="cm">                      * 判断当前输出的字符位置是否是sin曲线上的点对应的位置,
</span><span class="cm">                      * 如果是就输出&#39;@&#39;
</span><span class="cm">                      */</span>
                     <span class="k">if</span><span class="p">(</span><span class="n">i</span> <span class="o">==</span> <span class="n">offsetCenter</span><span class="o">+</span><span class="n">SIN_AMPLITUDE</span><span class="p">)</span>
                         <span class="n">printf</span><span class="p">(</span><span class="s">&#34;@&#34;</span><span class="p">);</span>
                 <span class="p">}</span>
                 <span class="c1">//代表这个方向是Y轴
</span><span class="c1"></span>                 <span class="n">printf</span><span class="p">(</span><span class="s">&#34;-&gt; Y</span><span class="se">\n</span><span class="s">&#34;</span><span class="p">);</span>
             <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
                 <span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">SIN_AMPLITUDE</span><span class="o">*</span><span class="mi">2</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">){</span>
                     <span class="c1">//判断当前输出的字符位置是否是sin曲线上的点对应的位置,如果是就输出&#39;*&#39;
</span><span class="c1"></span>                     <span class="k">if</span><span class="p">(</span><span class="n">i</span> <span class="o">==</span> <span class="p">(</span><span class="n">offsetCenter</span><span class="o">+</span><span class="n">SIN_AMPLITUDE</span><span class="p">)){</span>
                         <span class="n">printf</span><span class="p">(</span><span class="s">&#34;*&#34;</span><span class="p">);</span>
                     <span class="c1">//判断当前输出的字符位置是否是X轴上对应的位置,如果是就输出&#39;|&#39;
</span><span class="c1"></span>                     <span class="p">}</span><span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="n">i</span> <span class="o">==</span> <span class="n">SIN_AMPLITUDE</span><span class="p">){</span>
                         <span class="n">printf</span><span class="p">(</span><span class="s">&#34;|&#34;</span><span class="p">);</span>
                     <span class="p">}</span><span class="k">else</span><span class="p">{</span>
                         <span class="cm">/**
</span><span class="cm">                          * 这里主要是要处理一行里面除了画&#39;*&#39;、&#39;|&#39;、之外的&#39;-&#39;、&#39; &#39;
</span><span class="cm">                          * 其中的SIN_AMPLITUDE到SIN_AMPLITUDE+offsetCenter正好就是需要输出&#39;-&#39;的地方
</span><span class="cm">                          * 其他的地方输出&#39; &#39;
</span><span class="cm">                          */</span>
                         <span class="p">(((</span><span class="n">i</span> <span class="o">&gt;</span> <span class="n">SIN_AMPLITUDE</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="p">(</span><span class="n">i</span> <span class="o">&lt;</span> <span class="n">SIN_AMPLITUDE</span><span class="o">+</span><span class="n">offsetCenter</span><span class="p">))</span> <span class="o">||</span> \
                             <span class="p">((</span><span class="n">i</span> <span class="o">&lt;</span> <span class="n">SIN_AMPLITUDE</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="p">(</span><span class="n">i</span> <span class="o">&gt;</span> <span class="n">SIN_AMPLITUDE</span><span class="o">+</span><span class="n">offsetCenter</span><span class="p">)))</span> \
                                 <span class="o">?</span> <span class="n">printf</span><span class="p">(</span><span class="s">&#34;-&#34;</span><span class="p">)</span> <span class="o">:</span> <span class="n">printf</span><span class="p">(</span><span class="s">&#34; &#34;</span><span class="p">);</span>
                     <span class="p">}</span>
                     <span class="c1">//行尾,输出换行符
</span><span class="c1"></span>                     <span class="k">if</span><span class="p">(</span><span class="n">i</span> <span class="o">==</span> <span class="p">(</span><span class="n">SIN_AMPLITUDE</span><span class="o">*</span><span class="mi">2</span><span class="o">-</span><span class="mi">1</span><span class="p">))</span>
                         <span class="n">printf</span><span class="p">(</span><span class="s">&#34;</span><span class="se">\n</span><span class="s">&#34;</span><span class="p">);</span>
                 <span class="p">}</span>
             <span class="p">}</span>

             <span class="cm">/**
</span><span class="cm">              * 一行输出完成,为下一行输出作准备,下一行比上一行在角度上多加TRIANGLE/SIN_AMPLITUDE,
</span><span class="cm">              * 在本Demo中相当于360/20=18,也就是加18度.
</span><span class="cm">              */</span>
             <span class="n">currentInitAngle</span> <span class="o">+=</span> <span class="n">TRIANGLE</span><span class="o">/</span><span class="n">SIN_AMPLITUDE</span><span class="p">;</span>

             <span class="c1">//行号加1
</span><span class="c1"></span>             <span class="n">lineNumber</span><span class="o">++</span><span class="p">;</span>
         <span class="p">}</span>
         <span class="cm">/**
</span><span class="cm">          * 一屏图像输出完毕,最后输出一个换行符,并且延时一段时间再开始绘制下一屏图形
</span><span class="cm">          */</span>
         <span class="n">printf</span><span class="p">(</span><span class="s">&#34;</span><span class="se">\n</span><span class="s">&#34;</span><span class="p">);</span>
         <span class="n">usleep</span><span class="p">(</span><span class="n">DELAY_TIME</span><span class="p">);</span>
     <span class="p">}</span>

     <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
 <span class="p">}</span>
</code></pre></div><h4 id="编译运行">编译运行</h4>
<div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash">gcc sin-demo.c -lm -o a<span class="p">;</span>
./a out
</code></pre></div><blockquote>
<p>若编译时不使用-lm 参数则 math.h 库与 sin 函数会报错，原因是 gcc 的 sin 函数是定义在 libm.so 里，-l 选项定义指定的路径。不填写的话默认是/lib 和/usr/lib 内。
因为 linux 下所有的函数库都是以 lib 开头的。所以除去头和尾，那么 m 就是代表 libm.so（m 是库名，libm.so 是库文件名）
在使用“ -l”参数时，通常的习惯是除去“lib”函数库头和后面的版本号，使用库名和参数“-l”连接，形成“-lm”。于是，我们需要在 gcc 找不到库时，可是使用“-l”直接给定库名。</p>
</blockquote>
<h4 id="运行效果">运行效果</h4>
<p><img
        class="lazyload"
        src="../../svg/loading.min.svg"
        data-src="../../Project9/sin-demo.gif"
        data-srcset="../../Project9/sin-demo.gif, ../../Project9/sin-demo.gif 1.5x, ../../Project9/sin-demo.gif 2x"
        data-sizes="auto"
        alt="/Project9/sin-demo.gif"
        title="sin-demo" /></p>
<h3 id="实现-kbhit">实现 kbhit()</h3>
<p>检测 tty 输入的程序，远远超出了入门者的能力，你只需要会运行该程序，并将 snake 代码融入该代码。</p>
<ol>
<li>getchar 获得输入字符不需要按回车</li>
<li><strong>非阻塞</strong>得检测键盘输入</li>
<li>输入的字符<strong>不回显</strong></li>
</ol>
<p>代码来源: <a href="http://bbs.chinaunix.net/thread-935410-1-1.html" target="_blank" rel="noopener noreffer">Linux 下非阻塞地检测键盘输入的方法 (整理)</a></p>
<p>代码较长，请<strong>展开</strong>查看</p>
<div class="highlight"><pre class="chroma"><code class="language-c" data-lang="c"><span class="cp">#include</span> <span class="cpf">&lt;stdio.h&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;string.h&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;sys/time.h&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;sys/types.h&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;unistd.h&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;termios.h&gt;</span><span class="cp">
</span><span class="cp">#include</span> <span class="cpf">&lt;unistd.h&gt;</span><span class="cp">
</span><span class="cp"></span>
<span class="k">static</span> <span class="k">struct</span> <span class="n">termios</span> <span class="n">ori_attr</span><span class="p">,</span> <span class="n">cur_attr</span><span class="p">;</span>

<span class="k">static</span> <span class="kr">__inline</span>
<span class="kt">int</span> <span class="nf">tty_reset</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
<span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">tcsetattr</span><span class="p">(</span><span class="n">STDIN_FILENO</span><span class="p">,</span> <span class="n">TCSANOW</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">ori_attr</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span>
                <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>

        <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>


<span class="k">static</span> <span class="kr">__inline</span>
<span class="kt">int</span> <span class="nf">tty_set</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
<span class="p">{</span>

        <span class="k">if</span> <span class="p">(</span> <span class="n">tcgetattr</span><span class="p">(</span><span class="n">STDIN_FILENO</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">ori_attr</span><span class="p">)</span> <span class="p">)</span>
                <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>

        <span class="n">memcpy</span><span class="p">(</span><span class="o">&amp;</span><span class="n">cur_attr</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">ori_attr</span><span class="p">,</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">cur_attr</span><span class="p">)</span> <span class="p">);</span>
        <span class="n">cur_attr</span><span class="p">.</span><span class="n">c_lflag</span> <span class="o">&amp;=</span> <span class="o">~</span><span class="n">ICANON</span><span class="p">;</span>
<span class="c1">//        cur_attr.c_lflag |= ECHO;
</span><span class="c1"></span>        <span class="n">cur_attr</span><span class="p">.</span><span class="n">c_lflag</span> <span class="o">&amp;=</span> <span class="o">~</span><span class="n">ECHO</span><span class="p">;</span>
        <span class="n">cur_attr</span><span class="p">.</span><span class="n">c_cc</span><span class="p">[</span><span class="n">VMIN</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
        <span class="n">cur_attr</span><span class="p">.</span><span class="n">c_cc</span><span class="p">[</span><span class="n">VTIME</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>

        <span class="k">if</span> <span class="p">(</span><span class="n">tcsetattr</span><span class="p">(</span><span class="n">STDIN_FILENO</span><span class="p">,</span> <span class="n">TCSANOW</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">cur_attr</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span>
                <span class="k">return</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span>

        <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>

<span class="k">static</span> <span class="kr">__inline</span>
<span class="kt">int</span> <span class="nf">kbhit</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
<span class="p">{</span>

        <span class="n">fd_set</span> <span class="n">rfds</span><span class="p">;</span>
        <span class="k">struct</span> <span class="n">timeval</span> <span class="n">tv</span><span class="p">;</span>
        <span class="kt">int</span> <span class="n">retval</span><span class="p">;</span>

        <span class="cm">/* Watch stdin (fd 0) to see when it has input. */</span>
        <span class="n">FD_ZERO</span><span class="p">(</span><span class="o">&amp;</span><span class="n">rfds</span><span class="p">);</span>
        <span class="n">FD_SET</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">rfds</span><span class="p">);</span>
        <span class="cm">/* Wait up to five seconds. */</span>
        <span class="n">tv</span><span class="p">.</span><span class="n">tv_sec</span>  <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
        <span class="n">tv</span><span class="p">.</span><span class="n">tv_usec</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>

        <span class="n">retval</span> <span class="o">=</span> <span class="n">select</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">rfds</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">tv</span><span class="p">);</span>
        <span class="cm">/* Don&#39;t rely on the value of tv now! */</span>

        <span class="k">if</span> <span class="p">(</span><span class="n">retval</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="p">{</span>
                <span class="n">perror</span><span class="p">(</span><span class="s">&#34;select()&#34;</span><span class="p">);</span>
                <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
        <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">retval</span><span class="p">)</span>
                <span class="k">return</span> <span class="mi">1</span><span class="p">;</span>
        <span class="cm">/* FD_ISSET(0, &amp;rfds) will be true. */</span>
        <span class="k">else</span>
                <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
        <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>

<span class="c1">//将你的 snake 代码放在这里
</span><span class="c1"></span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
        <span class="c1">//设置终端进入非缓冲状态
</span><span class="c1"></span>        <span class="kt">int</span> <span class="n">tty_set_flag</span><span class="p">;</span>
        <span class="n">tty_set_flag</span> <span class="o">=</span> <span class="n">tty_set</span><span class="p">();</span>

        <span class="c1">//将你的 snake 代码放在这里
</span><span class="c1"></span>        <span class="n">printf</span><span class="p">(</span><span class="s">&#34;pressed `q` to quit!</span><span class="se">\n</span><span class="s">&#34;</span><span class="p">);</span>
        <span class="k">while</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="p">{</span>

                <span class="k">if</span><span class="p">(</span> <span class="n">kbhit</span><span class="p">()</span> <span class="p">)</span> <span class="p">{</span>
                        <span class="k">const</span> <span class="kt">int</span> <span class="n">key</span> <span class="o">=</span> <span class="n">getchar</span><span class="p">();</span>
                        <span class="n">printf</span><span class="p">(</span><span class="s">&#34;%c pressed</span><span class="se">\n</span><span class="s">&#34;</span><span class="p">,</span> <span class="n">key</span><span class="p">);</span>
                        <span class="k">if</span><span class="p">(</span><span class="n">key</span> <span class="o">==</span> <span class="sc">&#39;q&#39;</span><span class="p">)</span>
                                <span class="k">break</span><span class="p">;</span>
                <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
                       <span class="p">;</span><span class="c1">// fprintf(stderr, &#34;&lt;no key detected&gt;\n&#34;);
</span><span class="c1"></span>                <span class="p">}</span>
        <span class="p">}</span>

        <span class="c1">//恢复终端设置
</span><span class="c1"></span>        <span class="k">if</span><span class="p">(</span><span class="n">tty_set_flag</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
                <span class="n">tty_reset</span><span class="p">();</span>
        <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div><h4 id="编译运行-1">编译运行</h4>
<div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash">gcc kbhit.c -o a<span class="p">;</span>
./a out
</code></pre></div><h4 id="运行效果-1">运行效果</h4>
<p><img
        class="lazyload"
        src="../../svg/loading.min.svg"
        data-src="../../Project9/kbhit.gif"
        data-srcset="../../Project9/kbhit.gif, ../../Project9/kbhit.gif 1.5x, ../../Project9/kbhit.gif 2x"
        data-sizes="auto"
        alt="/Project9/kbhit.gif"
        title="kbhit" /></p>
<h2 id="编写智能算法">编写智能算法</h2>
<p>编写<strong>人工智能程序</strong>，使得 snake <strong>每秒自动走一步</strong>。</p>
<h3 id="程序要求">程序要求</h3>
<ol>
<li>请修改初始化字符矩阵，或者通过文件读入地图。地图中有一些你设定的障碍物（墙）</li>
<li>请实现如下算法决定蛇行走的方向</li>
<li>思考：一个<strong>长度为 5 的障碍物</strong>能困死该自动跑的蛇吗？</li>
</ol>
<h4 id="决定蛇行走的方向函数的伪代码">决定蛇行走的方向函数的伪代码</h4>
<pre><code class="language-code" data-lang="code">// Hx,Hy: 头的位置
// Fx,Fy：食物的位置
function whereGoNext(Hx,Hy,Fx,Fy) {
// 用数组movable[3]={“a”,”d”,”w”,”s”} 记录可走的方向
// 用数组distance[3]={0,0,0,0} 记录离食物的距离
// 分别计算蛇头周边四个位置到食物的距离。H头的位置，F食物位置
//     例如：假设输入”a” 则distance[0] = |Fx – (Hx-1)| + |Fy – Hy|
//           如果 Hx-1，Hy 位置不是Blank，则 distance[0] = 9999
// 选择distance中存最小距离的下标p，注意最小距离不能是9999
// 返回 movable[p]
}
</code></pre><h4 id="智能蛇的程序框架">智能蛇的程序框架</h4>
<pre><code class="language-code" data-lang="code">输出字符矩阵
WHILE not 游戏结束 DO
    wait(time)
    ch＝whereGoNext(Hx,Hy,Fx,Fy)
    CASE ch DO
    ‘A’:左前进一步，break
    ‘D’:右前进一步，break
    ‘W’:上前进一步，break
    ‘S’:下前进一步，break
    END CASE
    输出字符矩阵
END WHILE
输出 Game Over!!!
</code></pre><h4 id="函数设计">函数设计</h4>
<p>头部定义：
<img
        class="lazyload"
        src="../../svg/loading.min.svg"
        data-src="../../Project9/main.png"
        data-srcset="../../Project9/main.png, ../../Project9/main.png 1.5x, ../../Project9/main.png 2x"
        data-sizes="auto"
        alt="/Project9/main.png"
        title="main" /></p>
<h3 id="源代码">源代码</h3>
<p><a href="https://gitee.com/adbean/my-intelligent-snake" target="_blank" rel="noopener noreffer">gitee 仓库</a>：<a href="https://gitee.com/adbean/my-intelligent-snake">https://gitee.com/adbean/my-intelligent-snake</a></p>
<h3 id="运行效果-2">运行效果</h3>
<p><img
        class="lazyload"
        src="../../svg/loading.min.svg"
        data-src="../../Project9/intelligentSnake.gif"
        data-srcset="../../Project9/intelligentSnake.gif, ../../Project9/intelligentSnake.gif 1.5x, ../../Project9/intelligentSnake.gif 2x"
        data-sizes="auto"
        alt="/Project9/intelligentSnake.gif"
        title="intelligent snake" /></p>
<p>由于将地图<strong>长和宽</strong>提高了，并且将食物和蛇的<strong>最大长度提高</strong>，智能蛇可以不停地寻找食物并且自动前进。</p>
<p>但是当出现<strong>食物较多</strong>且<strong>智能蛇身体很长</strong>的时候，它还是会陷入自己<strong>撞上自己</strong>的困境，若要改变这种情况，就需要设计更好的算法来考虑多种情况，并且获得<strong>最优解</strong>。</p>
</div><div class="post-footer" id="post-footer">
    <div class="post-info">
        <div class="post-info-line">
            <div class="post-info-mod">
                <span>更新于 2020-12-27</span>
            </div>
            <div class="post-info-license"></div>
        </div>
        <div class="post-info-line">
            <div class="post-info-md"></div>
            <div class="post-info-share">
                <span></span>
            </div>
        </div>
    </div>

    <div class="post-info-more">
        <section class="post-tags"><i class="fas fa-tags fa-fw"></i>&nbsp;<a href="../../tags/%E9%A1%B9%E7%9B%AE/">项目</a>,&nbsp;<a href="../../tags/c%E8%AF%AD%E8%A8%80/">C语言</a>,&nbsp;<a href="../../tags/%E6%B8%B8%E6%88%8F/">游戏</a>,&nbsp;<a href="../../tags/%E8%B4%AA%E5%90%83%E8%9B%87/">贪吃蛇</a></section>
        <section>
            <span><a href="javascript:void(0);" onclick="window.history.back();">返回</a></span>&nbsp;|&nbsp;<span><a href="../../">主页</a></span>
        </section>
    </div>

    <div class="post-nav"><a href="../../posts/my-eighth-project/" class="prev" rel="prev" title="项目8：字符游戏-贪吃蛇"><i class="fas fa-angle-left fa-fw"></i>项目8：字符游戏-贪吃蛇</a>
            <a href="../../posts/my-tenth-project/" class="next" rel="next" title="流量为王的时代，拒绝虚假营销">流量为王的时代，拒绝虚假营销<i class="fas fa-angle-right fa-fw"></i></a></div>
</div>
</article></div>
            </main><footer class="footer">
        <div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.74.3">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="noopener noreffer" title="LoveIt 0.2.10"><i class="far fa-kiss-wink-heart fa-fw"></i> LoveIt</a>
                </div><div class="footer-line"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2020 - 2021</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="https://adbean.gitee.io/" target="_blank">Adbean</a></span>&nbsp;|&nbsp;<span class="license"><a rel="license external nofollow noopener noreffer" href="https://creativecommons.org/licenses/by-nc/4.0/" target="_blank">CC BY-NC 4.0</a></span></div>
        </div>
    </footer></div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-arrow-up fa-fw"></i>
            </a><a href="#" id="view-comments" class="fixed-button" title="查看评论">
                <i class="fas fa-comment fa-fw"></i>
            </a>
        </div><link rel="stylesheet" href="../../lib/katex/katex.min.css"><link rel="stylesheet" href="../../lib/katex/copy-tex.min.css"><script type="text/javascript" src="../../lib/smooth-scroll/smooth-scroll.min.js"></script><script type="text/javascript" src="../../lib/lazysizes/lazysizes.min.js"></script><script type="text/javascript" src="../../lib/clipboard/clipboard.min.js"></script><script type="text/javascript" src="../../lib/katex/katex.min.js"></script><script type="text/javascript" src="../../lib/katex/auto-render.min.js"></script><script type="text/javascript" src="../../lib/katex/copy-tex.min.js"></script><script type="text/javascript" src="../../lib/katex/mhchem.min.js"></script><script type="text/javascript">window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":50},"comment":{},"math":{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":true,"left":"\\[","right":"\\]"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"}],"strict":false}};</script><script type="text/javascript" src="../../js/theme.min.js"></script></body>
</html>
